﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Sagacity.NC.Web.Login" %>

<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>中考报名系统</title>
    <link rel="shortcut icon" href="resources/images/app.ico" />
    <script language="javascript" type="text/javascript">
        var roles = null;
        function onKeyDownDefault() 
        {
             if (window.event.keyCode == 13 && window.event.ctrlKey == false && window.event.altKey == false){ 
                 if (window.event.srcElement.type != "button") 
                     window.event.keyCode = 9; 
             } 
             else{ 
                 return true; 
             }
             btnLogin.onClick('');
        }
        
        function getUserRoles(){
            btnLogin.setDisabled(true);
            Coolite.AjaxMethods.GetUserRoles(txtUsername.getValue(),{
                success:function(reslut){
                    roles = eval(reslut);
                    cbRoles.getStore().removeAll();
                    
                    if(roles.length >= 1){
                        document.getElementById("roleSelector").style.display = roles.length > 1 ? "block" :"none";
                        for(var i = 0 ;i < roles.length ;i++){
                            cbRoles.insertItem(i, roles[i].Caption, roles[i].Id);
                        }
                        
                        cbRoles.setValue(roles[0].Id);
                        document.getElementById("hidSelectRole").value = roles[0].Id;
                    }
                    else{
                        document.getElementById("roleSelector").style.display = "none";
                    }
                    btnLogin.setDisabled(false);
                },
                failure:function(msg){
                    Ext.Msg.alert("错 误",msg);
                }
            });
        }
        
        function selRole(item){
            document.getElementById("hidSelectRole").value = item.data.value;
        }
    </script>
</head>
<body style=" background-image:url(resources/images/body_bg.gif)">
    <form id="form1" runat="server">
    <asp:HiddenField ID="hidSelectRole" runat="server" Value="0"/>
    <ext:ScriptManager ID="ScriptManager1" CleanResourceUrl="false" runat="server" />
    <ext:Window ID="winLogin" runat="server" Closable="false" Draggable="false" Resizable="false"
        Height="300" Icon="Lock" Title="中考报名系统" Width="630" BodyStyle="background-image: url(resources/images/clientlogo.jpg); ">
        <Body>
            <table>
                <tr style="height: 80px;">
                </tr>
                <tr>
                    <td style="width:80px;  padding-left:10px">
                        用户名
                    </td>
                    <td>
                        <ext:TextField ID="txtUsername" runat="server" EnableKeyEvents="true" FieldLabel="" AllowBlank="false" Width="180"
                            Text="" BlankText="请填写用户名">
                            <Listeners>
                                <KeyDown Handler="javascript:onKeyDownDefault()" />
                                <Blur Handler="javascript:getUserRoles();" />
                            </Listeners>
                        </ext:TextField>
                    </td>
                </tr>
                <tr>
                    <td style="width:80px; padding-left:10px">
                        密码
                    </td>
                    <td>
                        <ext:TextField ID="txtPassword" runat="server" InputType="Password" FieldLabel="" EnableKeyEvents="true"
                            AllowBlank="false" Text="" Width="180" BlankText="请填写密码">
                            <Listeners>
                                <KeyDown Handler="javascript:onKeyDownDefault()" />
                            </Listeners>
                        </ext:TextField>
                    </td>
                </tr>
                <tr>
                    <td style="width:80px; padding-left:10px">
                        业务处理日期
                    </td>
                    <td>
                        <ext:DateField ID="dateExcute" Width="180" AllowBlank="false" runat="server" InputType="Text" EnableKeyEvents="true"
                            Format="yyyy-MM-dd" BlankText="--请选择业务处理日期--">
                            <Listeners>
                                <KeyDown Handler="javascript:onKeyDownDefault()" />
                            </Listeners>
                        </ext:DateField>
                    </td>
                </tr>
                <tr id="roleSelector" runat="server">
                    <td style="width:80px; padding-left:10px">
                        角色选择
                    </td>
                    <td>
                        <ext:ComboBox ID="cbRoles" Width="180" Editable="false" AllowBlank="false" runat="server">
                            <Listeners>
                                <Select Handler="javascript:selRole(record);" />
                                <KeyDown Handler="javascript:onKeyDownDefault()" />
                            </Listeners>
                        </ext:ComboBox>
                    </td>
                </tr>
                <tr>
                    <td align="center">
                    </td>
                    <td>
                        <table>
                            <tr>
                                <td>
                                    <ext:Button ID="btnLogin" runat="server" Text="登 陆" AutoRender="true" Icon="Accept">
                                        <AjaxEvents>
                                            <Click OnEvent="btnLogin_Click">
                                                <EventMask ShowMask="true" Msg="正在登陆...." MinDelay="1000" />
                                            </Click>
                                        </AjaxEvents>
                                        <Listeners>
                                            <Click Handler="#{winLogin}.hide();" />
                                        </Listeners>
                                    </ext:Button>
                                </td>
                                <td>
                                    <ext:Button ID="Button1" runat="server" Text="重 置" Icon="RecordBlue">
                                        <Listeners>
                                            <Click Handler="#{txtUsername}.setValue('');#{txtPassword}.setValue('');" />
                                        </Listeners>
                                    </ext:Button>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr style="height: 100px;">
                </tr>
            </table>
        </Body>
        <BottomBar>
            <ext:StatusBar ID="sBar" Text="" StatusAlign="Right" runat="server">
            </ext:StatusBar>
        </BottomBar>
    </ext:Window>
    <script language="javascript" type="text/javascript">
        Ext.onReady(function(){
            document.getElementById("roleSelector").style.display = "none";
        });
    </script>
    </form>
</body>
</html>